package com.hefei.garden.controller;

import com.hefei.garden.pojo.KafkaBaseDto;
import com.hefei.garden.service.KafkaConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author: yxchen6
 * @date: 2022/8/7 13:10
 * @description:
 */
@RequestMapping("/kafkaConsumer")
@Controller
public class KafkaController {

    @Autowired
    private KafkaConsumerService kafkaConsumerService;

    @RequestMapping(value = "/getKafkaTopicPartition", method = RequestMethod.POST)
    @ResponseBody
    public List<Integer> getKafkaTopicPartition(@RequestBody KafkaBaseDto kafkaBaseDto) {
        return kafkaConsumerService.getKafkaTopicPartition(kafkaBaseDto);
    }

    /**
     * 单独启动一个（主题+组+分区）的消费者
     *
     * @param kafkaBaseDto
     */
    @RequestMapping(value = "/startKafkaDataPull", method = RequestMethod.POST)
    @ResponseBody
    public String startKafkaDataPull(@RequestBody KafkaBaseDto kafkaBaseDto) {
        return kafkaConsumerService.startKafkaDataPull(kafkaBaseDto);
    }

    /**
     * 单独停止一个（主题+组+分区）的消费者
     *
     * @param kafkaBaseDto
     */
    @RequestMapping(value = "/stopKafkaDataPull", method = RequestMethod.POST)
    @ResponseBody
    public String stopKafkaDataPull(@RequestBody KafkaBaseDto kafkaBaseDto) {
        return kafkaConsumerService.stopKafkaDataPull(kafkaBaseDto);
    }

}
